from repoze.who.interfaces import IMetadataProvider
from zope.interface import implements


class DummyMetadataProviderPlugin:
    implements(IMetadataProvider)

    def __init__(self, name):
        self.name = name

    # IMetadataProvider
    def add_metadata(self, environ, identity):
        # can't use dots in names in python string formatting :-(
        identity['__userid'] = identity['repoze.who.userid']
        del identity['__userid']
        identity[self.name] = {"display": "Test User"}


def make_dummy_metadata_plugin(name=None, **kw):
    if name is None:
        raise ValueError('name must be specified')
    return DummyMetadataProviderPlugin(name)
